<template>
  <s-layout
    title="我的"
    tabbar="/pages/index/user"
    navbar="normal"
    :bgStyle="template.style?.background"
    :navbarStyle="template.style?.navbar"
    onShareAppMessage
    :showFloatButton="true"
  >
    <view class="block-one">
	    <s-block v-for="(item, index) in template.data" :key="index" :styles="item.style">
		    <s-block-item :type="item.type" :data="item.data" :styles="item.style" />
	    </s-block>
	    <!--推送绑定面板-->
	    <s-notice-panel></s-notice-panel>
    </view>
  </s-layout>
</template>

<script setup>
import {computed, reactive} from 'vue';
  import { onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
  import sheep from '@/sheep';
import $platform from '@/sheep/platform';

  // 隐藏原生tabBar
  uni.hideTabBar();

  const template = computed(() => sheep.$store('app').template.user);
  const isLogin = computed(() => sheep.$store('user').isLogin);
  const goodsCard = {
	  "data": {
		  "mode": 1,
		  "goodsFields": {
			  "title": {
				  "show": 1,
			  },
			  "subtitle": {
				  "show": 1,
			  },
			  "price": {
				  "show": 1,
			  },
			  "original_price": {
				  "show": 1,
			  },
			  "sales": {
				  "show": 1,
			  },
			  "stock": {
				  "show": 0,
			  }
		  },
		  "buyNowStyle": {
			  // "mode": 1,
			  // "text": "立即下单",
			  // "color1": "#e16759",
			  // "color2": "#f5796f",
			  // "src": "\/storage\/decorate\/20221115\/4782356b4587dc4f4a218f2540a0bafc.png",
			  // "right": '20rpx',
			  // "bottom":"18rpx"
		  },
		  "tagStyle": {
			  "show": 1,
			  "src": "https://xiaozhan-shop.oss-cn-beijing.aliyuncs.com/2024/02/02708e08484a644ec69c24b02b92310a33mercari.png"
		  },
		  params: {
			  orderField: 'sort',
			  orderSort: 'asc'
		  },
		  "borderRadiusTop": 6,
		  "borderRadiusBottom": 6,
		  "space": 8
	  },
	  "style": {
		  "background": {
			  "type": "color",
			  "bgImage": "",
			  "bgColor": ""
		  },
		  "marginLeft": 8,
		  "marginRight": 8,
		  "marginTop": 0,
		  "marginBottom": 10,
		  "borderRadiusTop": 0,
		  "borderRadiusBottom": 0,
		  "padding": 0
	  }
  };
	const state = reactive({
		categoryId: '1328',
	})

  onShow(() => {
	  sheep.$store('app').init();
	  sheep.$store('user').updateUserData();
	  console.log(wx.canIUse("getUpdateManager"), "getUpdateManager")
	  if ($platform.name === 'WechatMiniProgram') {
		  if (wx.canIUse("getUpdateManager")) {
			  const updateManager = wx.getUpdateManager();
			  updateManager.onCheckForUpdate(function(res) { // 请求完新版本信息的回调
				  console.log(res, "是否有新版本")
				  if (res.hasUpdate) {
					  sheep.$helper.toast('检测到新版本，正在更新中...');
				  }
			  });
			  updateManager.onUpdateReady(function() {
				  wx.showModal({
					  title: '更新提示',
					  content: '新版本已经准备好，是否重启应用？',
					  success(res) {
						  if (res.confirm) {
							  updateManager.applyUpdate()
						  }
					  }
				  });
			  });
			  updateManager.onUpdateFailed(function() {
				  // 新的版本下载失败
				  wx.showModal({
					  title: "已经有新版本了哟~",
					  content: "新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~"
				  });
			  });
		  }
	  }
  });

  onPullDownRefresh(() => {
	  sheep.$store('user').updateUserData();
    sheep.$store('app').init();

    setTimeout(function () {
      uni.stopPullDownRefresh();
    }, 800);
  });

  onPageScroll(() => {});
</script>

<style>

.block-one {
	position: relative; /* 确保伪元素相对于 .block-one 定位 */
	background: #3E3A39; /* 原背景色 */
	padding: 1%;
}

.block-one::before {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;      /* 覆盖整个宽度 */
	height: 50rpx;      /* 顶部条的高度，可调整 */
	background-color: #F39800; /* 橙色条的颜色 */
}


.tag-bar {
	width: fit-content;
	background-image: linear-gradient(90deg, rgba(255, 135, 47, 0.98) 0%, #fad0c4 100%);
	background-position: left center;
	background-repeat: no-repeat;
	background-size: cover;
	color: #ffffff;
	font-weight: bold;
	font-size: 30rpx;
	padding: 5rpx;
	padding-left: 50rpx;
	padding-right: 50rpx;
	margin-bottom: 10rpx;
	font-style: italic
}

</style>
